package com.yanqu.road.server.logic.recharge.limit;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.cricket.CricketSystemConfig;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.server.gameplayer.module.cricket.CricketMgr;
import com.yanqu.road.server.gameplayer.module.cricket.CricketModule;
import com.yanqu.road.server.logic.recharge.limit.activity.BaseActivityMallLimit;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

public class CricketCourtMallLimit extends BaseActivityMallLimit {

    public CricketCourtMallLimit(long userId, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(userId, mallInfo, activityInfo);
    }

    @Override
    protected int activityCheck() {
        CricketSystemConfig config = CricketMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            if(config == null){
                logger.info("cricket count mall check config null");
            }
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        return 0;
    }

    @Override
    protected boolean isSystemUnLock() {
        return SystemOpenMgr.systemOpen(player, eSystemId.Cricket.getValue());
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        LimitBuyResult limitBuyResult = new LimitBuyResult();
        limitBuyResult.setLimitCount(1);
        return limitBuyResult;
    }

    @Override
    protected int logicCheck() {
        boolean buyToken = player.getModule(CricketModule.class).canRechargeToken(mallInfo);
        if (!buyToken) {
            return GameErrorCode.E_MALL_LIMIT_BUY;
        }
        return 0;
    }
}
